package com.jt.controller;

import com.jt.annotation.RequiredLog;
import com.jt.pojo.Staff;
import com.jt.service.StaffService;
import com.jt.vo.PageResult;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/staff")
public class StaffController {
    @Autowired
    private StaffService staffService;

    /**展现数据库信息
     */
    @GetMapping("/list")
//    @RequiredLog
    public SysResult getStaffList(PageResult pageResult){
        pageResult = staffService.getStaffList(pageResult);
        return SysResult.success(pageResult);
    }

    /**
     * 状态更新
     */
    @PutMapping("/status/{id}/{status}")
    @RequiredLog
    public SysResult updateStatus(Staff staff){
        staffService.updateStatus(staff);
        return SysResult.success();
    }

    /**
     * 根据id删除
     */
    @DeleteMapping("/{id}")
    @RequiredLog
    public SysResult deleteStaffById(@PathVariable Integer id){
        staffService.deleteStaffById(id);
        return SysResult.success();
    }

    /**实现新增
     */
    @PostMapping("/addStaff")
    @RequiredLog
    public SysResult addStaff(@RequestBody Staff staff){
        staffService.addStaff(staff);
        return SysResult.success();
    }

    /**根据ID查询数据库
     */
    @GetMapping("/{id}")
    @RequiredLog
    public SysResult getStaffById(@PathVariable Integer id){
        Staff staff =  staffService.getStaffById(id);
        return SysResult.success(staff);
    }

    /**实现修改操作
     */
    @PutMapping("/updateStaff")
    @RequiredLog
    public SysResult updateStaff(@RequestBody Staff staff){
        staffService.updateStaff(staff);
        return SysResult.success(staff);
    }
}